package com.wenan.ui.panels
{
	import flash.events.Event;
	
	import mx.containers.Canvas;
	import mx.controls.SWFLoader;
	import mx.core.FlexGlobals;
	
	public class LoadPanel extends Canvas
	{
		private var _loadding:Boolean = false;
		private var swfLoader:SWFLoader = null;
		
		public function LoadPanel()
		{
			super();
			
			width = 1004;
			height = 580;
			
			setStyle("backgroundAlpha", "0.5");
			setStyle("backgroundColor", "#FFFFFF");
			
			prepare();
		}
		
		public function get loadding():Boolean
		{
			return _loadding;
		}
		
		public function prepare():void
		{
			if (swfLoader == null)
			{
				swfLoader = new SWFLoader();
				swfLoader.alpha = 0.5;
				swfLoader.addEventListener(Event.COMPLETE, completeHandler);
				swfLoader.load("images/loading.swf"); 	
			}
			else
			{
				invalidateSwfLoader();
			}
		}

		private function completeHandler(event:Event):void
		{
			invalidateSwfLoader();
			
			addElement(swfLoader);	
		}
		
		private function invalidateSwfLoader():void
		{
			if (swfLoader && swfLoader.content)
			{
				var _x:Number = (width - swfLoader.content.width)/2;
				var _y:Number = (height - swfLoader.content.height)/2;
				swfLoader.x = _x;
				swfLoader.y = _y;	
			}
		}
	}
}